<template>
  <home-pannel title="新鲜好物" subTitle='新鲜出炉 品质靠谱'>
        <template #right>
          <More title="查看更多" path='/'></More>
        </template>
        <template #main>
          <ul ref="pannel" class="goods-list">
              <li v-for="item in list" :key="item.id">
                <RouterLink :to="`/detail/${item.id}`">
                  <img  v-lazyload='item.picture' alt="" />
                  <p class="name">{{ item.name }}</p>
                  <p class="price">&yen;{{ item.price }}</p>
                </RouterLink>
              </li>
        </ul>
        </template>
      </home-pannel>
</template>

<script>
import HomePannel from './home-pannel.vue'
import { findNew } from '@/api/home'
import { onMounted, ref } from 'vue'
export default {
  components: {
    HomePannel
  },
  setup () {
    // 1.定义响应式数据
    const list = ref([])
    // 2.定义函数 函数内部调用接口函数
    async function getList () {
      const res = await findNew()
      // console.log(res)
      list.value = res.result
    }
    // 3. onMounted中调用getList
    onMounted(() => {
      getList()
    })
    return {
      list
    }
  }
}
</script>

<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
